package cn.paul.service.impl;

import cn.paul.mapper.ItemMapper;
import cn.paul.pojo.Item;
import cn.paul.service.ItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl implements ItemService {
    @Autowired
    private ItemMapper itemMapper;

    //增删改查
    @Override
    public void addItem(Item item) {
        itemMapper.insertSelective(item);
    }

    @Override
    public void delete(int id) {
        itemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Item item) {
        itemMapper.updateByPrimaryKeySelective(item);
    }

    @Override
    public Item selectById(int id) {

        return itemMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Item> selectSelective(Item item, String pageNum, String pageSize) {
        if (pageNum == null) {
            pageNum = "1";
        }
        PageHelper.startPage(Integer.parseInt(pageNum), Integer.parseInt(pageSize));
        List<Item> itemList = itemMapper.selectSelective(item);
        PageInfo<Item> pageInfo = new PageInfo<>(itemList);
        return pageInfo;
    }
}
